<template>
    <div id="CampusManage">
        <el-row>
            <el-col :span="1" style="margin-bottom:20px">
                <el-button type="primary" @click="addNewCampus">新增学校</el-button>
            </el-col>
        </el-row>
        <el-row>
            <el-col>
                <table class="table table-bordered table-hover">
                    <tbody>
                        <tr>
                            <td>校区名</td>
                            <td>位置</td>
                            <td>负责人</td>
                            <td>联系电话</td>
                            <td>邮箱地址</td>
                            <td>校区简介</td>
                            <td>操作</td>
                        </tr>
                        <tr v-for="(item,key) in campus" :key="key">
                            <td>{{item.campusName}}</td>
                            <td>{{item.campusLocation}}</td>
                            <td style="width:80px">{{item.manager}}</td>
                            <td>{{item.mobile}}</td>
                            <td>{{item.email}}</td>
                            <td >{{item.description}}</td>
                            <td style="width:150px">
                                <el-button
                                size="mini"
                                @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                                <el-button
                                size="mini"
                                type="danger"
                                @click="handleDelete(key, item)">删除</el-button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </el-col>
        </el-row>
        <!-- <router-view></router-view> -->
        <AddCampusView v-if="show" 
            :isAddnew="isAddnew" 
            :isUpdate="isUpdate"
            :updateInfo="updateInfo"
            @hideView="hideView">
        </AddCampusView>
    </div>
</template>

<script>
import AddCampusView from './AddCampusView'
export default {
    data(){
        return {
            offset: 20,
            campus: [],
            show: false,
            isAddnew: true,
            isUpdate: false,
            updateInfo: {}
        }
    },
    components: {AddCampusView},
    methods: {
        addNewCampus(){
            // this.$router.push({name:'AddCampusView'})
            this.show = true;
            this.isAddnew = true;
            this.isUpdate = false;
        },
        handleEdit(index,row){
            this.show = true;
            this.isUpdate = true;
            this.isAddnew = false;
            this.updateInfo = row;
        },
        handleDelete(index,row){
            // 删除校区 /backstage/campus/delete
            var deleteURL = window.baseURL+"/backstage/campus/delete";
             this.$http.post(deleteURL,this.$qs.stringify({id: row.id,token:this.$token}))
                .then((response)=>{
                    if(response.data.success){
                        this.loadData();
                    }
                })
                .catch((error)=>{
            })
        },
        loadData(){
            // 加载数据 /backstage/campus/findByPage
            this.$http.get(window.baseURL+"/backstage/campus/findByPage?token="+this.$token)
            .then((response)=>{
                this.campus = response.data.data.list.results;
            })
            .catch((error)=>{
            })
        },
        hideView(){
            this.show = false;
            this.loadData();
        }
    },
    created(){
        this.loadData();
    }
}
</script>

<style lang="scss" scoped>
    #CampusManage {
        width: 100%;
        padding: 40px;
        box-sizing: border-box;
        position: absolute;
    }
</style>
